package com.chia.multienty.workflow.controller;

import com.chia.multienty.core.domain.basic.Result;
import com.chia.multienty.core.parameter.workflow.FlowableExamineParameter;
import com.chia.multienty.core.parameter.workflow.FlowableTaskClaimParameter;
import com.chia.multienty.core.parameter.workflow.FlowableTaskListGetParameter;
import com.chia.multienty.workflow.parameter.FlowableProcessInstanceDeleteParameter;
import com.chia.multienty.workflow.parameter.FlowableProcessInstanceListGetParameter;
import com.chia.multienty.workflow.service.FlowableProcessService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/flowable/process")
public class FlowableProcessController {

    @Autowired
    private FlowableProcessService flowableProcessService;
    @PostMapping("/instance/list")
    public Result<List<String>> getProcessInstanceList(@RequestBody FlowableProcessInstanceListGetParameter parameter) {
        List<String> processInsList = flowableProcessService.getProcessInsList(parameter);
        return new Result<>(processInsList);
    }
    @ApiOperation("删除流程实例")
    @DeleteMapping("/instance/delete")
    public Result<Boolean> deleteProcessInstance(@RequestBody FlowableProcessInstanceDeleteParameter parameter) {
        flowableProcessService.deleteProcessIns(parameter);
        return new Result<>(true);
    }

    @PostMapping("/my-task-list")
    public Result<List<Map<String, Object>>> getMyTaskList(@RequestBody FlowableTaskListGetParameter parameter) {
        List<Map<String, Object>> list = flowableProcessService.list(parameter);
        return new Result<>(list);
    }

    @ApiOperation("认领任务")
    @PostMapping("/task/claim")
    public Result<Void> claim(@RequestBody FlowableTaskClaimParameter parameter) {
        flowableProcessService.claim(parameter);
        return new Result<>();
    }
    @PostMapping("/task/examine")
    @ApiOperation("审批任务")
    public Result<Void> examine(@RequestBody FlowableExamineParameter parameter) {
        flowableProcessService.examine(parameter);
        return new Result<>();
    }
}
